<?php
class ml_model_rdsNotice extends ml_model_redis  
{    
    const NTCTYPE_ADDFANS = 'fans';
    const NTCTYPE_ADDSYSNOTICE = 'sysntc';
    const NTCTYPE_ADDCOMMENT = 'cmt';
    const NTCTYPE_ADDATTITUDE = 'atti';
    const NTCTYPE_ADDATME = 'atme';
    const NTCTYPE_PUBLICNOTICE = 'pubntc';
    
    private $_all_type = array(
        self::NTCTYPE_ADDATME ,
        self::NTCTYPE_ADDSYSNOTICE  ,
        self::NTCTYPE_ADDFANS  ,
        self::NTCTYPE_ADDCOMMENT  ,
        self::NTCTYPE_ADDATTITUDE  ,
    );
    
    const NOTICE_COUNT_PREFFIX = 'ntcC_';
    
    function __construct() {
        if(!$this->init_rds('meila_cache'))
            return false;
    }
    

    public function getNotice($uid)
    {
        
        $key = self::NOTICE_COUNT_PREFFIX.$uid;
        return $this->oRedis->hgetall($key);
    }
    
    public function add_notice($uid , $type)
    {
        $key = self::NOTICE_COUNT_PREFFIX.$uid;
        if(!in_array($type , $this->_all_type))
            return false;
        return $this->oRedis->hincrby($key ,  $type , 1);
    }
    
    public function clean_one_field($uid , $type)
    {
        $key = self::NOTICE_COUNT_PREFFIX.$uid;
        if(!in_array($type , $this->_all_type))
            return false;
        return $this->oRedis->hset($key ,  $type , 0);
    }
    
    public function clean_user_all($uid)
    {
        $key = self::NOTICE_COUNT_PREFFIX.$uid;
        foreach ($this->_all_type as $field)
        {
            $this->oRedis->hset($key , $field , 0);
        }
        $this->oRedis->hset($key , NTCTYPE_PUBLICNOTICE , time());
        return true;
    }
}

/*
$oRds = new ml_model_rdsNotice();
//加被表态
$oRds->add_notice($uid , ml_model_rdsNotice::NTCTYPE_ADDATTITUDE);
//加被评论
$oRds->add_notice($uid , ml_model_rdsNotice::NTCTYPE_ADDCOMMENT);
//加被关注
$oRds->add_notice($uid , ml_model_rdsNotice::NTCTYPE_ADDFANS);
*/